package com.reborn.mall.api.controller;

import com.reborn.mall.api.model.dto.OrderDTO;
import com.reborn.mall.api.model.entity.Order;
import com.reborn.mall.api.model.vo.OrderVO;
import com.reborn.mall.api.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单表-Controller
 *
 * @author wu.yue
 * @since 2020/3/12
 */
@RestController
@RequestMapping("/orders")
public class OrderController extends BaseController<Order> {

    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    public Order createOrder(@RequestBody OrderDTO orderDTO) {
        return orderService.createOrder(orderDTO);
    }

    @GetMapping("/list/{appUserId}")
    public List<OrderVO> listOrderVO(@PathVariable("appUserId") Long appUserId) {
        return orderService.findOrdersByAppUserId(appUserId);
    }

    @GetMapping("/get/{orderId}")
    public OrderVO getOrderVO(@PathVariable("orderId") Long orderId) {
        return orderService.findOrderByOrderId(orderId);
    }
}
